package test;

public class lc_283_move_zero {
    public static void main(String[] args) {
        moveZeroes(new int[]{0,1,0,3,12});
    }
    public static void moveZeroes1(int[] nums) {
        int n = nums.length;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if(nums[i] == 0)
                sum++;
        }
        for (int i = 0, j = 0; i < n; i++) {
            if(nums[i] != 0){
                nums[j] = nums[i];
                j++;
            }
        }
        for (int i = n - sum; i < n; i++) {
            nums[i] = 0;
        }
    }

    public static void moveZeroes(int[] nums) {
        int n = nums.length;
        int quick, slow;
        for (quick=0, slow = 0; quick < n; quick++) {
            if(nums[quick] != 0){
                nums[slow] = nums[quick];
                slow++;
            }
        }
        for (int i = slow; i < n; i++) {
            nums[i] = 0;
        }
    }
}
